package com.example.minefieldkeepercloud.view.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.minefieldkeepercloud.R;
import com.example.minefieldkeepercloud.util.DisplayUtil;
import com.example.minefieldkeepercloud.util.ToastUtil;


public class AddDialog extends Dialog {
    private Button btn_cancel, btn_update;
    private Activity context;
    private EditText edit_pool,edit_person;
    private OnAddClickListener onAddClickListener;

    public AddDialog(Activity context, int theme, OnAddClickListener onAddClickListener) {
        super(context, theme);
        this.context = context;
        this.onAddClickListener = onAddClickListener;

    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LayoutInflater inflater = LayoutInflater.from(getContext());
        View view = inflater.inflate(R.layout.dialog_add, null);
        setContentView(view, new ViewGroup.LayoutParams(DisplayUtil.getWidthPixels(context)-30,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        btn_cancel =  view.findViewById(R.id.btn_cancel);
        btn_update =  view.findViewById(R.id.btn_update);
        edit_pool =  view.findViewById(R.id.edit_pool);
        edit_person =  view.findViewById(R.id.edit_person);

        btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();


            }
        });
        btn_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(edit_pool.getText().toString().isEmpty()||edit_person.getText().toString().isEmpty())
                {
                    ToastUtil.showToast(context,"请填写矿池或矿工");
                }
                else
                {
                    onAddClickListener.add(edit_pool.getText().toString(),edit_person.getText().toString());
                    dismiss();
                }


            }
        });


    }

     public   interface OnAddClickListener { void add(String strKc,String strKg);}

}
